/**
 * Project of Vehicle Routing Problem with Time Windows implements 
 * some of well-known algorithms for solving VRPTW and presents new 
 * one.
 *
 * @author Michal Drobny  
 */

package io;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.Scanner;

/**
 * This class represents a CSV file reader. Contains methods useful for reading
 * files.
 * 
 * @author Michal Drobny
 * @date 24.11.2014
 */
public class CSVReader {

	private final Scanner scanner;

	/**
	 * Constructor.
	 * 
	 * @param path
	 *            The filename
	 * @throws FileNotFoundException If there is some problem through opening file
	 */
	public CSVReader(String path) throws FileNotFoundException {
		scanner = new Scanner(new FileInputStream(new File(path)));
	}

	/**
	 * Gets the line as a String.
	 * 
	 * @return The line
	 */
	public String getLine() {
		if (scanner.hasNextLine())
			return scanner.nextLine();
		else
			return "";
	}

	/**
	 * Closes the stream.
	 */
	public void close() {
		scanner.close();
	}

	/**
	 * Whether there is next integer in the stream.
	 * 
	 * @return Whether there is next integer in the stream
	 */
	public boolean hasInt() {
		return scanner.hasNextInt();
	}

	/**
	 * Gets the next integer in current stream.
	 * 
	 * @return next integer in current stream
	 */
	public int nextInt() {
		return scanner.nextInt();
	}
	
	/**
	 * Whether there is next long in the stream.
	 * 
	 * @return Whether there is next long in the stream
	 */
	public boolean hasLong() {
		return scanner.hasNextLong();
	}

	/**
	 * Gets the next long in current stream.
	 * 
	 * @return next long in current stream
	 */
	public long nextLong() {
		return scanner.nextLong();
	}

	/**
	 * Whether there is next string in the stream.
	 * 
	 * @return Whether there is next string in the stream
	 */
	public boolean hasString() {
		return scanner.hasNext();
	}

	/**
	 * Gets the next string in current stream.
	 * 
	 * @return next string in current stream
	 */
	public String nextString() {
		return scanner.next();
	}
}